package org.openweathermap.model;

import java.util.Arrays;
import java.util.Comparator;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class Cities {
	public int id;
	public String name;
	public float lat;
	public float lon;
	public String country;
	
	public static Cities[] parse(String json) {
		try {
			Gson gson = new GsonBuilder().create();
			Cities[] cities = gson.fromJson(json, Cities[].class);
			return Cities.sortByName(cities);
		} catch (Exception e) {
			return null;
		}
	}
	
	public static Cities[] sortByName(Cities[] arr){
		Arrays.sort(arr,new Comparator<Cities>(){  
		    @Override  
		    public int compare(Cities p1, Cities p2){
		         return p1.name.compareToIgnoreCase(p2.name);  
		   }  
		});
		return arr;
	}
}
